'use strict';

var mongoose = require('mongoose');
var db = require('../config/db.config');


module.exports.addColumn = function(params){
  var promise = new mongoose.Promise();

  var column = new db.column(params);
  column.save(function (error, data){
    if(error){
      promise.reject(error);
    }else{
      promise.complete(data);
    }
  });
  return promise;
};


module.exports.deleteColumn = function(id){
  var promise = new mongoose.Promise();

  db.column.findOneAndRemove({_id: id}, function (error, data){
    if(error){
      promise.reject(error);
    }else{
      promise.complete(data);
    }
  });
  return promise;
};


module.exports.getColumn = function(id){
  var promise = new mongoose.Promise();

  db.column.findById(id, function (error, data){
    if(error){
      promise.reject(error);
    }else{
      promise.complete(data);
    }
  });
  return promise;
};


module.exports.updateColumn = function(id, params){
  var promise = new mongoose.Promise();

  db.column.findByIdAndUpdate(id, params, function (error, data){
    if(error){
      promise.reject(error);
    }else{
      promise.complete(data);
    }
  });
  return promise;
};